package system

import (
	"github.com/gin-gonic/gin"
	"go_server/game_server/api/service/login"
	"go_server/game_server/dataconfig/config_manager"
	"go_server/game_server/world_manager"
	"net/http"
	"strconv"
)

//重载配置文件
func ReloadConfig(ctx *gin.Context) {
	config_manager.LoadAllGameData()
	ctx.String(http.StatusOK, "ReloadConfig successfully!!!!")
}

//获取在线玩家数量
func PlayerOnlineCount(ctx *gin.Context) {
	count := len(world_manager.WorldMgrObj.GetOnlinePlayersConn())
	ctx.String(http.StatusOK, "online count: %d", count)
}

func KickoutPlayer(ctx *gin.Context) {
	roleId, err := strconv.Atoi(ctx.Query("roleId"))
	if err != nil {
		ctx.String(http.StatusBadRequest, "param err!!")
		return
	}

	ok := login.KickOutPlayer(int64(roleId))
	if !ok {
		ctx.String(http.StatusBadRequest, "param err!!")
		return
	}
 	ctx.String(http.StatusOK, "player: %d has kicked out!!!!", roleId)
}

func KickoutAllPlayer(ctx *gin.Context) {
	ok := login.KickOutAllPlayer()
	if !ok {
		ctx.String(http.StatusBadRequest, "kick out all player failed!!!!")
		return
	}
	ctx.String(http.StatusOK, "kick out all player success!!!!")
}